#include "window_common.h"
#include "gkt_version.h"
#include "gkt_backboard.h"
enum {
	WIDGET_ID_TITLE = 0,
	WIDGET_ID_HW_V,
	WIDGET_ID_SW_V,
	WIDGET_ID_HW_V_DATA,
	WIDGET_ID_SW_V_DATA,
#if (defined(GKT_CONFIG_BACKBOARD_ENABLE) && GKT_CONFIG_BACKBOARD_ENABLE)
	WIDGET_ID_BB_SW_V,
	WIDGET_ID_BB_SW_V_DATA,
#else
	WIDGET_ID_RETURN,
#endif
	WIDGET_ID_MAX
};

GKT_WINDOW_WIDGET_DESCS_DEFINE(sysinfo) = {
	[WIDGET_ID_TITLE] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_MIDDLE | GKT_WIDGET_F_TITLE_MARK,
		WINDOW_FONT_NORMAL_SIZE, 
		WINDOW_TITLE_FG_COLOR, WINDOW_TITLE_BG_COLOR,
		0, 0, 
		WINDOW_WIDGET_DEFAULT_WIDTH, WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_system_info
	),	
	[WIDGET_ID_HW_V] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_LEFT,
		WINDOW_FONT_NORMAL_SIZE, WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		0, WINDOW_WIDGET_NORMAL_HEIGHT,
#if defined(GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE) \
	&& GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE		
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
#else
		WINDOW_FONT_NORMAL_SIZE * 2,
#endif
		WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_hardware_version
	),	
	[WIDGET_ID_SW_V] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_LEFT,
		WINDOW_FONT_NORMAL_SIZE, WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		0, WINDOW_WIDGET_NORMAL_HEIGHT * 2,
#if defined(GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE) \
	&& GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE			
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
#else
		WINDOW_FONT_NORMAL_SIZE * 2,
#endif
		WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_software_version
	),
	[WIDGET_ID_HW_V_DATA] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_LEFT,
		WINDOW_FONT_NORMAL_SIZE, WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
#if defined(GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE) \
	&& GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE		
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
		WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_FONT_NORMAL_SIZE * 3 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
#else
		WINDOW_FONT_NORMAL_SIZE * 2,
		WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_FONT_NORMAL_SIZE * 3 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
#endif
		WINDOW_WIDGET_NORMAL_HEIGHT,
		GKT_HW_VERSION_STRING
	),
#if defined(GKT_CONFIG_KX_VERSION) && GKT_CONFIG_KX_VERSION		
	[WIDGET_ID_SW_V_DATA] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_LEFT,
		WINDOW_FONT_NORMAL_SIZE,
		WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
		WINDOW_WIDGET_NORMAL_HEIGHT * 2,
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
		WINDOW_WIDGET_NORMAL_HEIGHT,
		GKT_SW_KX_VERSION_STRING
	),
#else
	[WIDGET_ID_SW_V_DATA] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_LEFT,
		WINDOW_FONT_NORMAL_SIZE,
		WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
#if defined(GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE) \
	&& GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE		
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
		WINDOW_WIDGET_NORMAL_HEIGHT * 2,
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
#else
		WINDOW_FONT_NORMAL_SIZE * 2,
		WINDOW_WIDGET_NORMAL_HEIGHT * 2,
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
#endif
		WINDOW_WIDGET_NORMAL_HEIGHT,
		GKT_SW_VERSION_STRING
	),
#endif
#if (defined(GKT_CONFIG_BACKBOARD_ENABLE) && GKT_CONFIG_BACKBOARD_ENABLE)
	[WIDGET_ID_BB_SW_V] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_LEFT,
		WINDOW_FONT_NORMAL_SIZE, WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		0, 
		WINDOW_WIDGET_NORMAL_HEIGHT * 3,
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2,
		WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_bb_software_version
	),
	[WIDGET_ID_BB_SW_V_DATA] = GKT_WIDGET_LABEL_DESC( 
		GKT_WIDGET_F_ALIGN_LEFT,
		WINDOW_FONT_NORMAL_SIZE, WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		WINDOW_FONT_NORMAL_SIZE * 4 + WINDOW_FONT_NORMAL_SIZE / 2 + 2, 
		WINDOW_WIDGET_NORMAL_HEIGHT * 3,
		WINDOW_FONT_NORMAL_SIZE * 3 + 2,
		WINDOW_WIDGET_NORMAL_HEIGHT,
		NULL
	),
#else
	[WIDGET_ID_RETURN] = GKT_WIDGET_LABEL_DESC(
		GKT_WIDGET_F_ALIGN_MIDDLE | GKT_WIDGET_F_ALIGN_CENTER,
		WINDOW_FONT_NORMAL_SIZE, WINDOW_DEFAULT_FG_COLOR, WINDOW_DEFAULT_BG_COLOR,
		(WINDOW_FONT_NORMAL_SIZE + 2) * 2, 
		WINDOW_WIDGET_NORMAL_HEIGHT * 3,
#if defined(GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE) \
	&& GKT_CONFIG_WINDOW_TEXT_CHINESE_ENABLE		
		(WINDOW_FONT_NORMAL_SIZE + 2) * 4,
#else
		(WINDOW_FONT_NORMAL_SIZE + 2) * 4 + WINDOW_FONT_NORMAL_SIZE/2,
#endif
		WINDOW_WIDGET_NORMAL_HEIGHT,
		WINDOW_TEXT_ID_return
	),
#endif
};

#if (defined(GKT_CONFIG_BACKBOARD_ENABLE) && GKT_CONFIG_BACKBOARD_ENABLE)
static char s_bb_sw_data[] = {'V', '0', '.', '0', '.', '0', 0};
#endif

static int window_sysinfo_event_handler(uint32_t major_type, 
				uint32_t minor_type, uint32_t widget_id, 
				uint32_t data)
{
	int retval = GKT_EVENT_HANDLE_CONTINUE;
	if (GKT_EVENT_WINDOW == major_type) {
		//if (GKT_WINDOW_INIT == minor_type) 
			//window_common_control_key_real_trim("sysinfo - INIT", 0);
		//else 
		if (minor_type == GKT_WINDOW_ACTIVE) {
			window_common_mask_except_cancel_ok();
					
#if (defined(GKT_CONFIG_BACKBOARD_ENABLE) && GKT_CONFIG_BACKBOARD_ENABLE)
			uint16_t bb_software_version = gkt_backboard_get_sw_version();
			s_bb_sw_data[1] = ((bb_software_version >> 8) & 0x000F) + '0';
			s_bb_sw_data[3] = ((bb_software_version >> 4) & 0x000F) + '0';
			s_bb_sw_data[5] = (bb_software_version & 0x000F) + '0';
			gkt_widget_set_data_by_id(WIDGET_ID_BB_SW_V_DATA, (uint32_t)&s_bb_sw_data);
#endif
		}
		//else if (GKT_WINDOW_UNINIT == minor_type)
			//window_common_control_key_real_trim("sysinfo - UNINIT", 1);
	}

	return retval;
}
GKT_WINDOW_DESC_DEFINE(sysinfo);


